#include "MenuState.h"
#include "TextureManager.h"
#include "Game.h"
#include <iostream>
#include "MenuButton.h"
#include "SoundManager.h"

std::string MenuState::m_menuID = "MENU";

MenuState::MenuState()
{
	// do nothing
}

MenuState::~MenuState()
{
	// do nothing
}

void MenuState::update()
{
	
	for (int i = 0; i < 2; i++)
	{
		m_menuObject[i]->update();
	}
}

void MenuState::render()
{
	mBackGroup->draw();
	for (int i = 0; i < 2; i++)
	{
		m_menuObject[i]->draw();
	}
}

bool MenuState::init()
{
	

	m_sprite_menu_state.loadFile("FileData/button.txt");
	mBackGroupSprite.loadFile("FileData/BackGroup.txt");
	mBackGroup = new GameObject();
	int id = 0;
	mBackGroup->add(mBackGroupSprite, id, TheGame::Instance()->getRenderer(), NULL);
	

	MenuButton* buttonPlay = new MenuButton(goToPlayGame, m_sprite_menu_state, 0, TheGame::Instance()->getRenderer());
	MenuButton* buttonExit = new MenuButton(goToExitGame, m_sprite_menu_state, 2, TheGame::Instance()->getRenderer());

	m_menuObject[0] = buttonPlay;
	m_menuObject[1] = buttonExit;
	/*TheSoundManager::Instance()->load("Sound/pacman_beginning.wav", "music", SOUND_MUSIC);
	TheSoundManager::Instance()->playMusic("music", 0);*/

	std::cout << "Menu state" << endl;

	return true;
}

bool MenuState::exit()
{

	TheTextureManager::Instance()->clearFromTextureMap("play"); 
	TheTextureManager::Instance()->clearFromTextureMap("exit");
	std::cout << "Exit menu state." << endl;

	return true;
}

void MenuState::goToPlayGame()
{
	std::cout << "Play button clicked." << endl;
	TheGame::Instance()->getStateMachine()->changeState(new PlayState());
}

void MenuState::goToExitGame()
{
	std::cout << "Exit button clicked." << endl;
	TheGame::Instance()->getRunning(0);
	TheGame::Instance()->quit();
}

std::string MenuState::getStateID() const
{
	return m_menuID;
}